using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Net;
using System.Text;
using System.Windows.Forms;

namespace Demo
{
	public class Form1 : Form
	{
		private IContainer components;

		private Button btnRequest;

		private TextBox txtURL;

		private Label label1;

		private TextBox txtParam;

		private Label label2;

		private Label label3;

		private ComboBox operateType;

		private TextBox txtRetData;
        private Label label5;
        private ComboBox comboBox1;
        private Label label4;

		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}

		private void InitializeComponent()
		{
            this.btnRequest = new System.Windows.Forms.Button();
            this.txtURL = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.txtParam = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.operateType = new System.Windows.Forms.ComboBox();
            this.txtRetData = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.comboBox1 = new System.Windows.Forms.ComboBox();
            this.SuspendLayout();
            // 
            // btnRequest
            // 
            this.btnRequest.Location = new System.Drawing.Point(662, 76);
            this.btnRequest.Name = "btnRequest";
            this.btnRequest.Size = new System.Drawing.Size(87, 42);
            this.btnRequest.TabIndex = 0;
            this.btnRequest.Text = "访问服务器";
            this.btnRequest.UseVisualStyleBackColor = true;
            this.btnRequest.Click += new System.EventHandler(this.btnRequest_Click);
            // 
            // txtURL
            // 
            this.txtURL.Location = new System.Drawing.Point(63, 22);
            this.txtURL.Name = "txtURL";
            this.txtURL.Size = new System.Drawing.Size(564, 21);
            this.txtURL.TabIndex = 1;
            this.txtURL.Text = "http://127.0.0.1:4530/api/face";
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(4, 26);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(53, 12);
            this.label1.TabIndex = 2;
            this.label1.Text = "完整地址";
            // 
            // txtParam
            // 
            this.txtParam.Location = new System.Drawing.Point(63, 56);
            this.txtParam.Multiline = true;
            this.txtParam.Name = "txtParam";
            this.txtParam.Size = new System.Drawing.Size(564, 62);
            this.txtParam.TabIndex = 3;
            this.txtParam.Text = "[{\"date_type\":\"face_command\",\"gateIp\":\"127.0.0.1\",\"out\":false,\"id\":70095064230631" +
    "9360,\"club_id\":111,\"sync_id\":700950642637669376,\"timestamp\":\"2018-06-13 15:03:18" +
    ".066\"}]";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(4, 59);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(53, 12);
            this.label2.TabIndex = 4;
            this.label2.Text = "提交数据";
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(633, 26);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(53, 12);
            this.label3.TabIndex = 5;
            this.label3.Text = "请求方式";
            // 
            // operateType
            // 
            this.operateType.FormattingEnabled = true;
            this.operateType.Items.AddRange(new object[] {
            "GET",
            "POST",
            "PUT",
            "DELETE"});
            this.operateType.Location = new System.Drawing.Point(692, 23);
            this.operateType.Name = "operateType";
            this.operateType.Size = new System.Drawing.Size(80, 20);
            this.operateType.TabIndex = 6;
            this.operateType.Text = "POST";
            // 
            // txtRetData
            // 
            this.txtRetData.Location = new System.Drawing.Point(63, 157);
            this.txtRetData.Multiline = true;
            this.txtRetData.Name = "txtRetData";
            this.txtRetData.Size = new System.Drawing.Size(709, 291);
            this.txtRetData.TabIndex = 7;
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(4, 160);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(53, 12);
            this.label4.TabIndex = 8;
            this.label4.Text = "返回数据";
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Location = new System.Drawing.Point(4, 133);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(53, 12);
            this.label5.TabIndex = 9;
            this.label5.Text = "数据类型";
            // 
            // comboBox1
            // 
            this.comboBox1.FormattingEnabled = true;
            this.comboBox1.Items.AddRange(new object[] {
            "application/json",
            "application/x-www-form-urlencoded",
            "multipart/form-data",
            "text/xml"});
            this.comboBox1.Location = new System.Drawing.Point(63, 130);
            this.comboBox1.Name = "comboBox1";
            this.comboBox1.Size = new System.Drawing.Size(249, 20);
            this.comboBox1.TabIndex = 10;
            this.comboBox1.Text = "application/x-www-form-urlencoded";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.BackColor = System.Drawing.SystemColors.InactiveCaption;
            this.ClientSize = new System.Drawing.Size(784, 452);
            this.Controls.Add(this.comboBox1);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.txtRetData);
            this.Controls.Add(this.operateType);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.txtParam);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.txtURL);
            this.Controls.Add(this.btnRequest);
            this.Name = "Form1";
            this.Text = "HTTP模拟请求工具";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

		}

		public Form1()
		{
			this.InitializeComponent();
		}

		private void btnRequest_Click(object sender, EventArgs e)
		{
			string userAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
			string text = this.txtURL.Text;
			string text2 = this.txtParam.Text;
			string text3 = this.operateType.Text;
			byte[] bytes = Encoding.UTF8.GetBytes(text2);
			try
			{
				HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(text);
				httpWebRequest.Method = text3;
				httpWebRequest.UserAgent = userAgent;
				httpWebRequest.ContentType = comboBox1.Text;
				if (text3 != "GET")
				{
					httpWebRequest.ContentLength = (long)bytes.Length;
					using (Stream requestStream = httpWebRequest.GetRequestStream())
					{
						requestStream.Write(bytes, 0, bytes.Length);
						HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
						StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.GetEncoding("utf-8"));
						string text4 = streamReader.ReadToEnd();
						this.txtRetData.Text = text4;
						goto IL_123;
					}
				}
				if (text3 == "GET")
				{
					HttpWebResponse httpWebResponse2 = (HttpWebResponse)httpWebRequest.GetResponse();
					StreamReader streamReader2 = new StreamReader(httpWebResponse2.GetResponseStream(), Encoding.GetEncoding("utf-8"));
					string text5 = streamReader2.ReadToEnd();
					this.txtRetData.Text = text5;
				}
				IL_123:;
			}
			catch (Exception ex)
			{
				this.txtRetData.Text = "the result: " + ex.ToString();
			}
		}

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
